/*
 * create:2016年4月16日 上午10:53:50
 * author:wangds  
 */
package net.wangds.comp.endpoint.http;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.wangds.common.context.Context;

/**
 * .
 * @author wangds
 *
 */
public interface HttpAccessContext extends Context{

  HttpServletRequest getRequest();
  HttpServletResponse getResponse();
  
  /**
   * obtain a request or a response.
   * @param <T> {@link HttpRequest} or {@link HttpResponse}.
   * @param inputs status id.
   * <p>
   * The first element of inputs is effective, and others was uneffective.
   * It must be "request","req","response",or "resp".
   * </p>
   * @return a request or a response.
   * <p>
   * The inputs[0] and return value table
   * <table>
   *  <tr><th>request</th><th>req</th><th>response</th><th>resp</th></tr>
   *  <tr><td>{@link #getRequest()}</td><td>{@link #getRequest()}</td><td>{@link #getResponse()}</td><td>{@link #getResponse()}</td></tr>
   * </table>
   * </p>
   */
  @SuppressWarnings("unchecked")
  @Override
  default <T> T status(Object... inputs) throws Exception {
    if(inputs.length>0){
      String id = String.valueOf(inputs[0]);
      if("request".equalsIgnoreCase(id)||"req".equalsIgnoreCase(id)){
        return (T)this.getRequest();
      }else if("response".equalsIgnoreCase(id)||"resp".equalsIgnoreCase(id)){
        return (T)this.getResponse();
      }
    }
    return null;
  }
  
}
